package com.cyw.generator.com.service.impl;

import com.cyw.generator.com.entity.TbGraphRelation;
import com.cyw.generator.com.mapper.TbGraphRelationMapper;
import com.cyw.generator.com.service.ITbGraphRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.xiaohai.generator.common.domain.JsonBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaohai.generator.common.domain.PageEntity;
import com.xiaohai.generator.common.domain.ReturnPageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Cyw
 * @since 2022-09-28
 */
@Service
public class TbGraphRelationServiceImpl extends ServiceImpl<TbGraphRelationMapper, TbGraphRelation> implements ITbGraphRelationService {

    @Override
    public JsonBean add(TbGraphRelation tbGraphRelation){
        baseMapper.insert(tbGraphRelation);
        return JsonBean.returnResponse();
    }

    @Override
    public JsonBean delete(Long id){
        baseMapper.deleteById(id);
        return JsonBean.returnResponse();
    }

    @Override
    public JsonBean updateData(TbGraphRelation tbGraphRelation){
        baseMapper.updateById(tbGraphRelation);
        return JsonBean.returnResponse();
    }

    @Override
    public JsonBean findById(Long id){
        TbGraphRelation tbGraphRelation = baseMapper.selectById(id);
        return JsonBean.returnResponse(tbGraphRelation);
    }
    @Override
    public JsonBean findListByPage(PageEntity page, TbGraphRelation tbGraphRelation){
        QueryWrapper<TbGraphRelation> wrapper = new QueryWrapper<>();
        if (page.isPaginated()) {
            IPage<TbGraphRelation> wherePage = new Page<>(page.getPageNum(),page.getPageSize());
            IPage<TbGraphRelation> iPage = baseMapper.selectPage(wherePage, wrapper);
            return JsonBean.returnResponse(ReturnPageData.fillingData(iPage.getTotal(), iPage.getRecords()));
        }else{
            return JsonBean.returnResponse(baseMapper.selectList(wrapper));
        }
    }
}
